package com.yc.vote.controller;


import com.yc.vote.entity.Record;
import com.yc.vote.entity.User;
import com.yc.vote.service.BizException;
import com.yc.vote.service.IRecordService;
import com.yc.vote.vo.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 投票系统-投票记录表-6 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2024-04-14
 */
@RestController
@RequestMapping("/vote/record")
public class RecordController {

    @Resource
    IRecordService recordService;

    @RequestMapping("commit")
    public Result commit(
            @RequestBody List<Record> records,
            @SessionAttribute User loginedUser) throws BizException {
        for (Record record : records) {
            record.setUsid(loginedUser.getId());
        }
        recordService.commit(records);
        return new Result(1,"投票成功!",records);
    }

}

